home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / wfc007.000 / src / cserver.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-22  |  7.0 KB  |  362 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like.
  10. */
  11.  
  12. #if defined( _DEBUG )
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. IMPLEMENT_SERIAL( CServer, CNetwork, 1 )
  18.  
  19. CServer::CServer()
  20. {
  21.    m_Initialize();
  22. }
  23.  
  24. CServer::CServer( LPCTSTR machine_name )
  25. {
  26.    Open( machine_name );
  27. }
  28.  
  29. CServer::~CServer()
  30. {
  31.    Close();
  32. }
  33.  
  34. void CServer::Close( void )
  35. {
  36.    CNetwork::Close();
  37.    m_Initialize();
  38. }
  39.  
  40. void CServer::GetComment( CString& comment )
  41. {
  42.    comment.Empty();
  43.  
  44.    /*
  45.    ** Test m_ServerName of emptiness because a lot of comments are blank
  46.    */
  47.  
  48.    if ( m_Retrieved102 != TRUE )
  49.    {
  50.       m_Get_102_Data();
  51.    }
  52.  
  53.    comment = m_Comment;
  54. }
  55.  
  56. void CServer::GetDomain( CString& name )
  57. {
  58.    name.Empty();
  59.  
  60.    /*
  61.    ** Yes, domain is a member of the 503 structure, but that call doesn't work.
  62.    ** We've got to use 599. Although for numsessions we have to use 503, go figure
  63.    */
  64.  
  65.    if ( m_Retrieved599 != TRUE )
  66.    {
  67.       m_Get_599_Data();
  68.    }
  69.  
  70.    name = m_Domain;
  71. }
  72.  
  73. DWORD CServer::GetMajorVersion( void )
  74. {
  75.    if ( m_Retrieved102 != TRUE )
  76.    {
  77.       m_Get_102_Data();
  78.    }
  79.  
  80.    return( m_MajorVersion );
  81. }
  82.  
  83. DWORD CServer::GetMinorVersion( void )
  84. {
  85.    if ( m_Retrieved102 != TRUE )
  86.    {
  87.       m_Get_102_Data();
  88.    }
  89.  
  90.    return( m_MinorVersion );
  91. }
  92.  
  93. DWORD CServer::GetNumberOfOpens( void )
  94. {
  95.    if ( m_Retrieved503 != TRUE )
  96.    {
  97.       m_Get_503_Data();
  98.    }
  99.  
  100.    return( m_NumberOfOpens );
  101. }
  102.  
  103. DWORD CServer::GetNumberOfUsers( void )
  104. {
  105.    if ( m_Retrieved503 != TRUE )
  106.    {
  107.       m_Get_503_Data();
  108.    }
  109.  
  110.    return( m_NumberOfUsers );
  111. }
  112.  
  113. void CServer::GetName( CString& name )
  114. {
  115.    name.Empty();
  116.  
  117.    if ( m_Retrieved102 != TRUE )
  118.    {
  119.       m_Get_102_Data();
  120.    }
  121.  
  122.    name = m_MachineName;
  123. }
  124.  
  125. DWORD CServer::GetPlatform( void )
  126. {
  127.    if ( m_Retrieved102 != TRUE )
  128.    {
  129.       m_Get_102_Data();
  130.    }
  131.  
  132.    return( m_Platform );
  133. }
  134.  
  135. void CServer::GetPlatformName( CString& name )
  136. {
  137.    name.Empty();
  138.  
  139.    /*
  140.    ** Test m_ServerName of emptiness because a lot of comments are blank
  141.    */
  142.  
  143.    if ( m_Retrieved102 != TRUE )
  144.    {
  145.       m_Get_102_Data();
  146.    }
  147.  
  148.    switch( m_Platform )
  149.    {
  150.       case SV_PLATFORM_ID_OS2:
  151.  
  152.          name = "OS/2";
  153.          return;
  154.  
  155.       case SV_PLATFORM_ID_NT:
  156.  
  157.          name = "NT";
  158.          return;
  159.  
  160.       default:
  161.  
  162.          CString temp_name( "" );
  163.  
  164.          temp_name.Format( "Unknown Type %d", m_Platform );
  165.          name = temp_name;
  166.          return;
  167.    }
  168. }
  169.  
  170. void CServer::GetPlatformNameAndVersion( CString& name )
  171. {
  172.    name.Empty();
  173.  
  174.    CString temp_name;
  175.  
  176.    GetPlatformName( temp_name );
  177.  
  178.    name.Format( "%s %d.%d", (LPCTSTR) temp_name, m_MajorVersion, m_MinorVersion );
  179. }
  180.  
  181. DWORD CServer::GetType( void )
  182. {
  183.    if ( m_Retrieved102 != TRUE )
  184.    {
  185.       m_Get_102_Data();
  186.    }
  187.  
  188.    return( m_Type );
  189. }
  190.  
  191. void CServer::GetUserPath( CString& path )
  192. {
  193.    path.Empty();
  194.  
  195.    if ( m_Retrieved102 != TRUE )
  196.    {
  197.       m_Get_102_Data();
  198.    }
  199.  
  200.    path = m_UserPath;
  201. }
  202.  
  203. DWORD CServer::GetUsers( void )
  204. {
  205.    if ( m_Retrieved102 != TRUE )
  206.    {
  207.       m_Get_102_Data();
  208.    }
  209.  
  210.    return( m_Users );
  211. }
  212.  
  213. void CServer::m_Get_102_Data( void )
  214. {
  215.    LPBYTE buffer = (LPBYTE) NULL;
  216.  
  217.    /*
  218.    ** One of the children got loose in the header files again...
  219.    **
  220.    ** Also, we can't get 101 information because it doesn't work if you supply
  221.    ** a machine name... Go Figure...
  222.    */
  223.  
  224.    ::NetServerGetInfo( (LPTSTR) m_WideMachineName, 102, &buffer );
  225.  
  226.    if ( buffer != NULL )
  227.    {
  228.       SERVER_INFO_102 *information_p = (SERVER_INFO_102 *) buffer;
  229.  
  230. #if ! defined( UNICODE )
  231.       ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv102_name,     information_p->sv102_name     );
  232.       ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv102_comment,  information_p->sv102_comment  );
  233.       ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv102_userpath, information_p->sv102_userpath );
  234. #endif
  235.  
  236.       /*
  237.       ** Now store the info we want...
  238.       */
  239.  
  240.       m_MachineName  = information_p->sv102_name;
  241.       m_UserPath     = information_p->sv102_userpath;
  242.       m_Users        = information_p->sv102_users;
  243.       m_Comment      = information_p->sv102_comment;
  244.       m_Platform     = information_p->sv102_platform_id;
  245.       m_MajorVersion = information_p->sv102_version_major;
  246.       m_MinorVersion = information_p->sv102_version_minor;
  247.       m_Type         = information_p->sv102_type;
  248.       m_Retrieved102 = TRUE;
  249.    }
  250. }
  251.  
  252. void CServer::m_Get_503_Data( void )
  253. {
  254.    LPBYTE buffer = (LPBYTE) NULL;
  255.  
  256.    /*
  257.    ** One of the children got loose in the header files again...
  258.    */
  259.  
  260.    ::NetServerGetInfo( (LPTSTR) m_WideMachineName, 503, &buffer );
  261.  
  262.    if ( buffer != NULL )
  263.    {
  264.       SERVER_INFO_503 *information_p = (SERVER_INFO_503 *) buffer;
  265.  
  266.       /*
  267.       ** Now store the info we want...
  268.       */
  269.  
  270.       m_NumberOfUsers = information_p->sv503_sessusers;
  271.       m_NumberOfOpens = information_p->sv503_sessopens;
  272.       m_Retrieved503  = TRUE;
  273.    }
  274. }
  275.  
  276. void CServer::m_Get_599_Data( void )
  277. {
  278.    LPBYTE buffer = (LPBYTE) NULL;
  279.  
  280.    /*
  281.    ** One of the children got loose in the header files again...
  282.    */
  283.  
  284.    ::NetServerGetInfo( (LPTSTR) m_WideMachineName, 599, &buffer );
  285.  
  286.    if ( buffer != NULL )
  287.    {
  288.       SERVER_INFO_599 *information_p = (SERVER_INFO_599 *) buffer;
  289.  
  290. #if ! defined( UNICODE )
  291.  
  292.       if ( information_p->sv599_domain != NULL )
  293.       {
  294.          ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv599_domain, information_p->sv599_domain );
  295.       }
  296.       else
  297.       {
  298.          information_p->sv599_domain = " ";
  299.       }
  300.  
  301. #endif
  302.  
  303.       /*
  304.       ** Now store the info we want...
  305.       */
  306.  
  307.       m_Domain       = information_p->sv599_domain;
  308.       m_Retrieved599 = TRUE;
  309.    }
  310. }
  311.  
  312. void CServer::m_Initialize( void )
  313. {
  314.    m_Comment.Empty();
  315.    m_UserPath.Empty();
  316.  
  317.    m_Retrieved102 = FALSE;
  318.    m_Retrieved503 = FALSE;
  319.    m_Retrieved599 = FALSE;
  320.  
  321.    m_MajorVersion  = 0;
  322.    m_MinorVersion  = 0;
  323.    m_NumberOfUsers = 0;
  324.    m_NumberOfOpens = 0;
  325.    m_Platform      = 0;
  326.    m_Type          = 0;
  327.    m_Users         = 0;
  328. }
  329.  
  330. void CServer::Serialize( CArchive& archive )
  331. {
  332.    CNetwork::Serialize( archive );
  333.  
  334.    if ( archive.IsStoring() )
  335.    {
  336.       archive << m_Comment;
  337.       archive << m_UserPath;
  338.       archive << m_Domain;
  339.       archive << m_MajorVersion;
  340.       archive << m_MinorVersion;
  341.       archive << m_NumberOfOpens;
  342.       archive << m_NumberOfUsers;
  343.       archive << m_Platform;
  344.       archive << m_Type;
  345.       archive << m_Users;
  346.    }
  347.    else
  348.    {
  349.       archive >> m_Comment;
  350.       archive >> m_UserPath;
  351.       archive >> m_Domain;
  352.       archive >> m_MajorVersion;
  353.       archive >> m_MinorVersion;
  354.       archive >> m_NumberOfOpens;
  355.       archive >> m_NumberOfUsers;
  356.       archive >> m_Platform;
  357.       archive >> m_Type;
  358.       archive >> m_Users;
  359.    }
  360. }
  361.  
  362.